package com.ec.kafka.controller;

import com.ec.core.common.core.api.ResponseMsg;
import com.ec.core.common.core.api.Result;
import com.ec.core.kafka.utils.KafkaUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Eric Lee
 * @since 2022-07-13 18:20
 */
@Slf4j
@RestController
@RequestMapping("test")
public class TestController {
    @Value("${spring.kafka.producer.ec-topic}")
    private String topic;

    @GetMapping("/kafka")
    @Transactional(rollbackFor = Exception.class)//不加事务会报错
    public Result<Void> sendMsg(@RequestParam("msg") String msg) {
        KafkaUtil.sendTopicMessage(topic, msg);
        return ResponseMsg.success();
    }
}
